<template>
  <div 
    ref="wrapper"
    class="wrapper">
    <div class="contents">
       <slot></slot>
    </div>
  </div>
</template>

<script>
import BScroll from '@better-scroll/core'
import Pullup from '@better-scroll/pull-up'
  BScroll.use(Pullup)
export default {
  name: 'Scroll',
  data () {
    return {
      scroll: null
    }
  },
  props: {
    Types:{
      type: Number,
      default: 0
    },
    Loads:{
      type: Boolean,
      default: false
    }
  },
  mounted () {
    this.scroll = new BScroll (this.$refs.wrapper, {
      click: true,
      probeType: this.Types,
      pullUpLoad: this.Loads
    })
    //监听滚动位置
    this.scroll.on('scroll', (option) => {
      this.$emit('scrollClick', option)
    })
    //监听上拉事件
    if (this.pullUpLoad === true) {
      this.scroll.on('pullingUp', () => {
      this.$emit('pullingUp')
    })
    }
  },
  methods: {
    refresh () {
      this.scroll && this.scroll.refresh()
    },
    scrollTo ( x,y, time=300 ) {
      this.scroll && this.scroll.scrollTo( x, y, time )
    },
    finishPullUp () {
      this.scroll && this.scroll.finishPullUp()
    }
  }
}
</script>

<style scoped>
</style>>